package com.gae.blore.client.dialog;

import com.gae.blore.client.domain.Hospital;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class HospitalDialog extends DialogBox {

	final Label specLab = new Label("Specialization");
	final Label phoneLab = new Label("Phone");
	final Label urlLab = new Label("URL");
	final Label emailLab = new Label("Email");
	final Label numLab = new Label("Number of Beds");
	final Label workingLab = new Label("Working Hours");

	public HospitalDialog(Hospital hospital) {

		initWidget(hospital);
	}

	private void initWidget(Hospital hospital) {

		setText("Hospital Details");
		setAnimationEnabled(true);
		final Button closeButton = new Button("Close");

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");

		final String specVal = hospital.getSpec();
		final String phoneVal = hospital.getPhone();
		final String urlVal = hospital.getUrl();
		final String emailVal = hospital.getEmail();
		final Integer numVal = hospital.getNumOfBeds();
		final String workingVal = hospital.getWorkingHrs();

		final HTML phoneText = new HTML((null == phoneVal ? " " : phoneVal));
		final HTML urlText = new HTML((null == urlVal ? " " : urlVal));
		final HTML emailText = new HTML((null == emailVal ? " " : emailVal));

		final HTML specText = new HTML((null == specVal ? " " : specVal));
		final HTML numText = new HTML((null == numVal) ? " "
				: numVal.toString());
		final HTML workingText = new HTML((null == workingVal ? " "
				: workingVal));

		final HTML sep = new HTML(":");

		FlexTable flexTable = new FlexTable();

		PlaceFiller.fillPlace(hospital, flexTable);

		flexTable.setWidget(3, 0, phoneLab);
		flexTable.setWidget(3, 1, sep);
		flexTable.setWidget(3, 2, phoneText);
		flexTable.setWidget(4, 0, urlLab);
		flexTable.setWidget(4, 1, sep);
		flexTable.setWidget(4, 2, urlText);
		flexTable.setWidget(5, 0, emailLab);
		flexTable.setWidget(5, 1, sep);
		flexTable.setWidget(5, 2, emailText);
		flexTable.setWidget(6, 0, specLab);
		flexTable.setWidget(6, 1, sep);
		flexTable.setWidget(6, 2, specText);
		flexTable.setWidget(7, 0, numLab);
		flexTable.setWidget(7, 1, sep);
		flexTable.setWidget(7, 2, numText);
		flexTable.setWidget(8, 0, workingLab);
		flexTable.setWidget(8, 1, sep);
		flexTable.setWidget(8, 2, workingText);

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.add(flexTable);
		// dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);

		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
		// horizontalPanel.s

		horizontalPanel.add(closeButton);
		dialogVPanel.add(horizontalPanel);
		setWidget(dialogVPanel);

		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				HospitalDialog.this.hide();
			}
		});

	}
}
